package com.db.sevent;

import java.awt.Image;
import java.awt.Toolkit;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;

import com.data.Data;
import com.db.service.WorkUserServer;
import com.view.P1;
import com.view.P2;
import com.view.P3;

/**
* @author 作者:秋哲    E-mail:2810201146@qq.com:
* @version 创建时间：2020年5月30日 下午9:38:19
* @description: 
*/
public class WorkUserEvent {
	public  void upWorkUserList() {
		int listIndexByGUI = P1.instance.list01.getSelectedIndex();
		HashMap<String, DefaultListModel<String>> map = new WorkUserServer().getClassUserWorkList(listIndexByGUI );
		upWorkUserListSetData(map);
	}
	public  void upWorkUserListSetData(HashMap<String, DefaultListModel<String>> map) {
		P2.instance.list02.setModel(map.get("list02"));
		P2.instance.list03.setModel(map.get("list03"));
		P2.instance.list04.setModel(map.get("list04"));
		P2.instance.list05.setModel(map.get("list05"));
		P2.instance.list06.setModel(map.get("list06"));
		P2.instance.lb1.setText("已交："+map.get("list02").size());
		P2.instance.lb2.setText("通过："+map.get("list03").size());
		P2.instance.lb3.setText("未通过:"+map.get("list04").size());
		P2.instance.lb4.setText("跳过："+map.get("list05").size());
		P2.instance.lb5.setText("未交："+map.get("list06").size());
		P2.instance.lb01.setText("上交情况："+Data.workUserMap.size()+"/"+Data.userAll.size());
	}
	public void auditUserWork(String state) {
		//从界面上拿到选中的学生姓名
		String userNameByGUI = P2.instance.selectName;
		int selectedIndex = P2.instance.selectList.getSelectedIndex();
		if(userNameByGUI==null) {
			P3.instance.setImgBoxData("");
			return;
		};
		WorkUserServer server = new WorkUserServer();
		int n = server.auditUserWork(userNameByGUI, state);
		if(n==1) {
			HashMap<String, DefaultListModel<String>> map = server.upworkUserAll();
			upWorkUserListSetData(map);
			//继续显示下一个学生作业
			P2.instance.selectList.setSelectedIndex(selectedIndex);
		}else {
			System.out.println("更新失败！");
		}
		// 但执行到最后一个人的时候发现没有选中的人了，就会清空显示的图片
		userNameByGUI = P2.instance.selectName;
		if(userNameByGUI==null) {
			P3.instance.setImgBoxData("");
		};
	}
	
	public void getUserWork() {
		String userNameByGUI = P2.instance.selectName;
		String url = new WorkUserServer().getUserWork(userNameByGUI);
		System.out.println(url);
		P3.instance.setImgBoxData(url);
//		P3.instance.imgBox.setIcon(new ImageIcon(url));
	}
}
